<template>
  <label class="sxk-radio" :class="{ 'is-checked': label === value }">
    <span class="sxk-radio-input">
      <span class="sxk-radio-inner"></span>
      <input
        class="sxk-radio-original"
        type="radio"
        :value="label"
        :name="name"
        v-model="model"
      />
    </span>
    <span class="sxk-radio-label">
      <slot></slot>
      <template v-if="!$slots.default">{{ label }}</template>
    </span>
  </label>
</template>

<script>
export default {
  name: 'sxk-radio',
  props: {
    label: {
      type: [String, Number, Boolean],
      default: ''
    },
    // 值
    value: null,

    name: {
      type: String,
      default: ''
    }
  },

  computed: {
    model: {
      get () {
        return this.value
      },
      set (value) {
        this.$emit('input', value)
      }
    }
  }
}
</script>

<style lang="less" scoped>
.sxk-radio {
  margin: 20px;
  color: #606266;
  position: relative;
  font-weight: bold;
  cursor: pointer;
  display: inline-block;
  outline: none;
  line-height: 1;
  white-space: nowrap;
  font-size: 14px;
  margin-right: 30px;
  .sxk-radio-input {
    white-space: nowrap;
    outline: none;
    cursor: pointer;
    display: inline-block;
    line-height: 1;
    position: relative;
    vertical-align: middle;
    .sxk-radio-inner {
      border: 1px solid #dcdfe6;
      border-radius: 100%;
      width: 14px;
      height: 14px;
      background-color: #fff;
      display: inline-block;
      position: relative;
      cursor: pointer;
      box-sizing: border-box;
      &:after {
        width: 4px;
        height: 4px;
        border-radius: 100%;
        position: absolute;
        background-color: #fff;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0);
        transform: transform 0.15s ease-in;
        content: '';
      }
    }
    .sxk-radio-original {
      opacity: 0;
      outline: none;
      position: absolute;
      z-index: -1;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: 0;
    }
  }
  .sxk-radio-label {
    font-size: 14px;
    padding-left: 10px;
  }
}
.sxk-radio.is-checked {
  .sxk-radio-input {
    .sxk-radio-inner {
      border: 1px solid #409eff;
      background-color: #409eff;
      &:after {
        transform: translate(-50%, -50%) scale(1);
      }
    }
  }
  .sxk-radio-label {
    color: #409eff;
  }
}
</style>
